<template>
  <div class="state-box">
    <!-- <p class="state-title">状态：{{ statusMap[statusDetail] }}</p> -->
    <div class="step-state">
      <div class="step-state-item completed">
        <span>创建完成</span>
      </div>
      <span class="step-state-adorn"></span>
      <div
        :class="['step-state-item', { 'padding': countStatus(statusDetail) >= 0 }, { 'flicker': statusDetail == 'Pending' }]">
        <span>等待中</span>
      </div>
      <span class="step-state-adorn"></span>
      <div
        :class="['step-state-item', { 'running': countStatus(statusDetail) >= 1 }, { 'flicker': statusDetail == 'Running' }]">
        <span>运行中</span>
      </div>
      <span class="step-state-adorn"></span>
      <div
        :class="['step-state-item', { 'succeeded': countStatus(statusDetail) >= 2 }, { 'flicker': statusDetail == 'Succeeded' }]">
        <span>成功</span>
      </div>

      <span class="step-state-adorn"></span>
      <div :class="['step-state-item', { 'failed': statusDetail == 'Failed' }]">
        <span>失败</span>
      </div>

      <span class="step-state-adorn"></span>
      <div
        :class="['step-state-item', { 'terminated': statusDetail == 'terminated' }, { 'flicker': statusDetail == 'Succeeded' }]">
        <span>停止</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      statusDetail: '',
      // stateMap: [
      //   {val: 'Pending', key: '等待中'},
      //   {val: 'Running', key: '运行中'},
      //   {val: 'Succeeded', key: '成功'},
      //   {val: 'Failed', key: '停止/失败'},
      //   {val: 'Failed', key: '未知'}
      // ]
      stateMap: ['Pending', 'Running', 'Succeeded', 'terminated', 'Failed']
    };
  },
  props: ['statusStr'],
  watch: {
    statusStr(val) {
      this.statusDetail = val
    }
  },
  methods: {
    countStatus(state) {
      return this.stateMap.indexOf(state)
    }
  },
  mounted() {
    this.statusDetail = this.statusStr
    console.log("statusDetail", this.statusDetail)
  },
};
</script>
<style scoped lang="less">
.state-title {
  font-weight: bold;
  color: #606266;
  line-height: 28px;
  padding: 16px 16px 0;
  font-size: 20px;
}

.step-state {
  width: 100%;
  display: flex;
  box-sizing: border-box;
  padding: 8px 40px;
  height: 52px;

  .step-state-adorn {
    flex: 1;
    height: 1px;
    background: #C0C4CC;
    overflow: hidden;
    margin-top: 6px;
  }

  .step-state-item {
    width: 14px;
    height: 14px;
    position: relative;
    border-radius: 7px;
    background: #AAAAAA;

    span {
      position: absolute;
      left: 50%;
      top: 22px;
      display: block;
      width: 100px;
      text-align: center;
      transform: translate(-50%, 0);
    }
  }

  .completed {
    background: #67C23A;
  }

  .padding {
    background: #67C23A;
  }

  .deploying {
    background: #67C23A;
  }

  .running {
    background: #67C23A;
  }

  .succeeded {
    background: #67C23A;
  }

  .terminated {
    background: #000;
  }

  .failed {
    background: #E90000;
  }

  .flicker {
    animation: flickeranimation 1.2s infinite;
  }
}

@keyframes flickeranimation {
  0% {
    opacity: 1;
  }

  50% {
    opacity: .3;
  }

  100% {
    opacity: 1;
  }
}
</style>